﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using MySql.Data.MySqlClient;

namespace ConexionBD
{
    public partial class FormElimNota : Form
    {
        MySqlConnection Conexion = new MySqlConnection();
        public string stConsulta;
        string opcion1;
        string opcion2;
        public FormElimNota()
        {
            InitializeComponent();
        }

        private void FormElimNota_Load(object sender, EventArgs e)
        {
            Nota nnn = new Nota();
            DataTable dt = new DataTable();
            dt = nnn.elimNota1();
            try
            {
                for (int i = 0; i < dt.Rows.Count; i++)
                    comboBox1.Items.Add(dt.Rows[i]["nombre_libreta"]);
            }

            catch (MySqlException error)
            {
                throw error;
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            Nota notag = new Nota();
            int selectedIndex = comboBox1.SelectedIndex;
            Object selectedItem = comboBox1.SelectedItem;
            opcion1 = selectedItem.ToString();

            DataTable dt2 = new DataTable();



            dt2 = notag.llenarCombo2(opcion1);
            try
            {
                for (int i = 0; i < dt2.Rows.Count; i++)
                    comboBox2.Items.Add(dt2.Rows[i]["titulo"]);
            }

            catch (MySqlException error)
            {
                throw error;
            }
        }

        private void button3_Click(object sender, EventArgs e)
        {
            Nota notax = new Nota();
            int selectedIndex2 = comboBox2.SelectedIndex;
            Object selectedItem2 = comboBox2.SelectedItem;
            opcion2 = selectedItem2.ToString();
            DataTable dt3 = new DataTable();
            dt3 = notax.verTexto(opcion2);
            richTextBox1.Text = dt3.Rows[0]["texto"].ToString();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Nota notax = new Nota();
            int selectedindex1 = comboBox1.SelectedIndex;
            Object selectedItem1 = comboBox1.SelectedIndex;
            opcion1 = selectedItem1.ToString();
            int selectedIndex2 = comboBox2.SelectedIndex;
            Object selectedItem2 = comboBox2.SelectedItem;
            opcion2 = selectedItem2.ToString();
            notax.eliminarNota(opcion1, opcion2);

            
            
        }
    }
}
